home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 422_02 / misc / castle.c < prev    next >
C/C++ Source or Header  |  1994-03-20  |  46KB  |  1,441 lines

  1. /*
  2.  * This is a text based adventure game which I wrote a number of
  3.  * years ago (on a unix system), and have since ported to the PC
  4.  * using MICRO-C.
  5.  *
  6.  * With thanks to Crowther and Woods who wrote the original FORTRAN
  7.  * adventure game from which this game borrows several ideas.
  8.  *
  9.  * Copyright 1983-1994 Dave Dunfield
  10.  * All rights reserved.
  11.  *
  12.  * Permission granted for personal (non-commercial) use only.
  13.  *
  14.  * Compile command: cc castle -fop
  15.  */
  16. #include <stdio.h>
  17.  
  18. #define OBJECTS            41        /* number of objects */
  19. #define LOCS            181        /* number of locations */
  20. #define DARK            16        /* first location where its dark */
  21. #define DOORS            14        /* number of doors */
  22. #define MONSTERS        12        /* number of monsters */
  23. #define CARRY            5        /* carry limit */
  24. #define STARTING_HITS    50        /* starting number of hit points */
  25. #define LAMP_DIM_1        250        /* first warning */
  26. #define LAMP_DIM_2        300        /* second warning */
  27. #define LAMP_DIE        350        /* lamp dies */
  28. #define RESUME_TIME        30        /* number of minites before he can resume */
  29. #define EXTRA_POINTS    9        /* extra points for not breaking vase */
  30.  
  31. /* game status data, all data from 'prop' to start of 'inbuf' (exclusive) */
  32. /* is saved in the file 'castle.sav' when game is suspended */
  33.     char prop[OBJECTS] = { 0 };
  34.     char door_stat[DOORS]= { 0 };
  35.     unsigned location[OBJECTS] = {
  36.         6, 4, 39, 8, 77, 33, 18, -1, 21, 24, 29,
  37.         92, 64, 108, 10, 144, 146, -1, -1, -1,
  38.         31, 67, 115, 65, 105, 79, 141, 41, 42, 117, -1,
  39.         -1, 96, 12, 90, 163, 128, 124, 11, 135, 164 };
  40.     char lstate = 1, died = 0, found_chest = 0;
  41.     unsigned carry = 0, turns = 0, lturns = 0, current_loc = 1,
  42.         old_loc = 1, deep = 0;
  43.     int hits = STARTING_HITS;
  44.     int monster_hits[] = {            /* monsters current hit points */
  45.         10, 20, 25, 30, 40, 55, 60, 60, 75, 50, 100, 100 };
  46.     unsigned monster_loc[] = {        /* monsters current location */
  47.         15, 25, 41, 55, 69, 83, 97, 111, 125, 139, 153, 167 };
  48.     unsigned date[2] = { 0 };
  49.  
  50.     char inbuf[80], *inptr;        /* input buffer and pointer */
  51.     unsigned places[LOCS];            /* stores pointers to descriptions */
  52.     char vocabulary[] = {        /* known words */
  53. /* verbs */
  54.         'g','o'+128,                1,
  55.         'r','u','n'+128,            1,
  56.         'w','a','l','k'+128,        1,
  57.         't','a','k','e'+128,        2,
  58.         'g','r','a','b'+128,        2,
  59.         'g','e','t'+128,            2,
  60.         'd','r','o','p'+128,        3,
  61.         'd','i','g'+128,            4,
  62.         'l','i','g','h','t'+128,    5,
  63.         'o','n'+128,                5,
  64.         'o','f','f'+128,            6,
  65.         'o','p','e','n'+128,        7,
  66.         'u','n','l','o','c','k'+128,7,
  67.         'm','o','v','e'+128,        7,
  68.         'p','u','s','h'+128,        7,
  69.         'r','e','m','o','v','e'+128,7,
  70.         'c','l','o','s','e'+128,    8,
  71.         'l','o','c','k'+128,        8,
  72.         'l','o','o','k'+128,        9,
  73.         'v','i','e','w'+128,        9,
  74.         'i','n','v','e','n','t','o','r','y'+128,    10,
  75.         'c','a','r','r','y'+128,    10,
  76.         'q','u','i','t'+128,        11,
  77.         's','t','o','p'+128,        11,
  78.         'r','e','a','d'+128,        12,
  79.         'w','a','v','e'+128,        13,
  80.         'r','u','b'+128,            13,
  81.         'o','p','e','r','a','t','e'+128, 13,
  82.         'u','s','e'+128,            13,
  83.         'a','b','r','a','c','a','d','a','b','r','a'+128, 14,
  84.         'h','o','k','u','s'+128,14,
  85.         'p','o','k','u','s'+128,14,
  86.         's','e','s','a','m','e'+128,14,
  87.         's','h','a','z','a','m'+128,14,
  88.         'p','l','u','g','h'+128,    14,
  89.         'x','y','z','z','y'+128,    14,
  90.         'f','a','r','l','e','y'+128,15,
  91.         's','u','s','p','e','n','d'+128,16,
  92.         'r','e','s','u','m','e'+128,17,
  93.         'a','t','t','a','c','k'+128,18,
  94.         's','w','i','n','g'+128,    18,
  95.         's','t','a','b'+128,        18,
  96.         't','h','r','u','s','t'+128,18,
  97.         'k','i','l','l'+128,        18,
  98.         'h','i','t'+128,            18,
  99.         'd','r','i','n','k'+128,    19,
  100.         'e','m','p','t','y'+128,    20,
  101.         'd','u','m','p'+128,        20,
  102.         's','p','i','l','l'+128,    20,
  103.         'r','e','t','r','e','a','t'+128,21,
  104.         'b','a','c','k','u','p'+128,21,
  105.         'l','a','s','t'+128,        21,
  106.         'b','a','c','k'+128,        21,
  107.         'o','u','t'+128,            21,
  108.         'o','i','l'+128,            22,
  109.         'l','u','b','r','i','c','a','t','e'+128,22,
  110.         's','c','o','r','e'+128,    23,
  111.         'p','o','i','n','t','s'+128,23,
  112.         's','h','i','t'+128,        24,
  113.         'f','u','c','k'+128,        24,
  114.         'd','a','m','n'+128,        24,
  115.         'p','i','s','s'+128,        24,
  116. /* nouns */
  117.         'g','a','t','e'+128,        50,
  118.         'g','r','a','t','e'+128,    50,
  119.         'f','e','n','c','e'+128,    50,
  120.         'd','o','o','r'+128,        50,
  121.         's','l','a','b'+128,        50,
  122.         's','i','g','n'+128,        50,
  123.         'b','o','o','k','c','a','s','e'+128,    50,
  124.         's','h','e','l','v','e','s'+128, 50,
  125.         's','h','e','l','f'+128,    50,
  126.         'b','a','r','s'+128,        50,
  127.         'c','e','l','l'+128,        50,
  128.         'p','i','t'+128,            51,
  129.         'h','o','l','e'+128,        51,
  130.         's','t','a','i','r','s'+128,52,
  131.         'l','a','d','d','e','r'+128,52,
  132.         'w','a','l','l'+128,        53,
  133.         'c','a','v','e'+128,        53,
  134.         'c','a','v','e','r','n'+128,53,
  135.         'g','r','o','u','n','d'+128,53,
  136.         'f','l','o','o','r'+128,    53,
  137. /* objects */
  138.         'l','a','m','p'+128,        100,
  139.         'l','a','n','t','e','r','n'+128,100,
  140.         'k','e','y'+128,            101,
  141.         'r','o','p','e'+128,        102,
  142.         's','t','r','i','n','g'+128,102,
  143.         'c','o','r','d'+128,        102,
  144.         'k','n','i','f','e'+128,    103,
  145.         'd','a','g','g','e','r'+128,103,
  146.         'a','x','e'+128,            104,
  147.         'h','a','t','c','h','e','t'+128,104,
  148.         's','w','o','r','d'+128,    105,
  149.         'h','i','l','t'+128,        105,
  150.         's','a','c','k'+128,        106,
  151.         'b','a','g'+128,            106,
  152.         'b','a','t','t','e','r','i','e','s'+128,107,
  153.         'b','a','t','t','e','r','y'+128,107,
  154.         'b','a','r'+128,            108,
  155.         'c','r','o','w','b','a','r'+128,108,
  156.         'r','o','d'+128,            109,
  157.         'w','a','n','d'+128,        109,
  158.         's','c','r','o','l','l'+128,110,
  159.         'p','a','p','e','r'+128,    110,
  160.         'r','o','l','l'+128,        110,
  161.         'p','o','t','i','o','n'+128,111,
  162.         'b','o','t','t','l','e'+128,111,
  163.         'f','l','a','s','k'+128,    112,
  164.         'l','i','q','u','i','d'+128,112,
  165.         'v','e','l','v','e','t'+128,113,
  166.         'p','i','l','l','o','w'+128,113,
  167.         'r','o','c','k'+128,        114,
  168.         's','t','o','n','e'+128,    114,
  169.         'p','u','r','p','l','e'+128,114,
  170.         'c','a','n','n','o','n'+128,115,
  171.         'b','a','l','l'+128,        115,
  172.         'm','e','t','a','l'+128,    116,
  173.         'd','e','t','e','c','t','o','r'+128,116,
  174. /* treasure objects */
  175.         'c','o','i','n','s'+128,    120,
  176.         'm','o','n','e','y'+128,    120,
  177.         'r','i','n','g'+128,        121,
  178.         'b','a','n','d'+128,        121,
  179.         's','t','a','t','u','e'+128,122,
  180.         'c','r','y','s','t','a','l'+128,122,
  181.         'd','r','a','g','o','n'+128,122,
  182.         'i','v','o','r','y'+128,    123,
  183.         'a','m','u','l','e','t'+128,123,
  184.         'e','b','o','n','y'+128,    124,
  185.         'g','l','o','b','e'+128,    124,
  186.         'c','r','o','w','n'+128,    125,
  187.         'd','i','a','m','o','n','d'+128,126,
  188.         'g','o','l','d'+128,        127,
  189.         'n','u','g','g','e','t'+128,127,
  190.         'n','u','g','g','e','t','s'+128,127,
  191.         'p','r','e','c','i','o','u','s'+128,128,
  192.         'j','e','w','e','l','s'+128,128,
  193.         'j','e','w','e','l','r','y'+128,128,
  194.         'p','l','a','t','i','n','u','m'+128,129,
  195.         'p','y','r','a','m','i','d'+128,129,
  196.         'c','h','e','s','t'+128,    130,
  197.         't','r','e','a','s','u','r','e'+128,130,
  198.         'e','m','e','r','a','l','d'+128,131,
  199.         'e','a','r','r','i','n','g'+128,131,
  200.         'r','a','r','e'+128,        132,
  201.         's','p','i','c','e'+128,    132,
  202.         's','p','i','c','e','s'+128,132,
  203.         'p','e','r','s','i','a','n'+128,133,
  204.         'r','u','g'+128,            133,
  205.         'r','u','b','y'+128,        134,
  206.         's','t','a','f','f'+128,    134,
  207.         'm','i','n','g'+128,        135,
  208.         'v','a','s','e'+128,        135,
  209.         's','i','l','v','e','r'+128,136,
  210.         'p','e','n','d','a','n','t'+128,136,
  211.         'p','a','i','n','t','i','n','g'+128,137,
  212.         'a','r','t'+128,            137,
  213.         'b','r','o','n','z','e'+128,138,
  214.         'c','a','n','d','l','e'+128,138,
  215.         'c','a','n','d','l','e','s','t','i','c','k'+128,138,
  216.         's','i','l','k'+128,        139,
  217.         'j','a','c','k','e','t'+128,139,
  218.         's','i','l','k','e','n'+128,139,
  219.         'c','o','a','t'+128,        139,
  220.         'b','o','o','k'+128,        140,
  221.         'b','i','b','l','e'+128,    140,
  222.         'l','e','a','t','h','e','r'+128, 140,
  223. /* directions */
  224.         'n','o','r','t','h'+128,    240,
  225.         'n'+128,                    240,
  226.         'e','a','s','t'+128,        241,
  227.         'e'+128,                    241,
  228.         's','o','u','t','h'+128,    242,
  229.         's'+128,                    242,
  230.         'w','e','s','t'+128,        243,
  231.         'w'+128,                    243,
  232.         'u','p'+128,                244,
  233.         'u'+128,                    244,
  234.         'd','o','w','n'+128,        245,
  235.         'd'+128,                    245,
  236. /* filler words, not actually looked at, but no message given is used */
  237.         's','a','y'+128,            0,
  238.         't','h','e'+128,            0,
  239.         'a'+128,                    0,
  240.         'w','i','t','h'+128,        0,
  241.         't','u','r'